package com.cashmama.market.api.domain.handler.order;

import com.cashmama.market.api.domain.service.ApiProductService;
import com.cashmama.market.api.domain.service.OrderService;
import com.cashmama.market.api.domain.vo.RequestLocalInfo;
import com.cashmama.market.api.domain.vo.order.RepaymentRecordVO;
import com.cashmama.market.api.infras.enums.PackageNameEnum;
import com.cashmama.market.api.infras.enums.ProductCategoryEnum;
import com.qianli.cashmama.product.facade.result.ProductCategory;
import com.qianli.cashmama.trade.client.vo.TradeVO;
import org.apache.commons.collections.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: market-api
 * @description
 * @author: frank
 * @create: 2020-07-09 16:02
 **/
@Component
public class LoanZoneHandler extends BaseHandler{

    @Autowired
    private OrderService orderService;
    @Autowired
    private ApiProductService apiProductService;

    @PostConstruct
    public void init(){
        OrdersHandler.orderHandlerMap.put(PackageNameEnum.LOANZONE.getLowercaseName(), this);
    }

    @Override
    public List<RepaymentRecordVO> getOderList(List<TradeVO> tradeList, Integer type) {
        return ListUtils.EMPTY_LIST;
    }

    @Override
    public String getCategoryCode() {
        List<ProductCategory> productCategoryList = apiProductService.getActiveProductCategoryList(RequestLocalInfo.getRequestBasicInfo().getAppCode());
        List<ProductCategory> newUserProductCategories = productCategoryList.stream().filter(productCategory -> ProductCategoryEnum.LOAN_ZONE.getCode().equalsIgnoreCase(productCategory.getCode())).collect(Collectors.toList());
        return newUserProductCategories.get(0).getCode();
    }

    @Override
    public List<ProductCategory> getProductCategoryList(String appCode) {
        List<ProductCategory> productCategoryList = apiProductService.getActiveProductCategoryList(appCode);
        return productCategoryList.stream().filter(productCategory -> ProductCategoryEnum.LOAN_ZONE.getCode().equalsIgnoreCase(productCategory.getCode())).collect(Collectors.toList());
    }
}
